package com.xxh.blog.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xxh.blog.entity.UserMessage;
import com.xxh.blog.service.UserMessageService;
import com.xxh.blog.shiro.AccountProfile;
import com.xxh.blog.utils.Result;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class messageController {


    @Resource
    UserMessageService userMessageService;

    /**
     * 取得用户未读消息数量
     * @return
     */
    @RequestMapping("/message/nums")
    @ResponseBody
    public Result getMessageNum(){


        AccountProfile Curuser=(AccountProfile) SecurityUtils.getSubject().getPrincipal();

        int count = userMessageService.count(new QueryWrapper<UserMessage>()
                .eq("to_user_id", Curuser.getId())
                .eq("status", 0));
        return Result.ok("请求成功").put("count",count).put("status", 0);
    }
}
